package com.qf.oa_system.service.impl;

import com.qf.oa_system.entity.Student;
import com.qf.oa_system.entity.StudentAndSingleScore;
import com.qf.oa_system.entity.Teacher;
import com.qf.oa_system.entity.Weekly;
import com.qf.oa_system.mapper.StudentDao;
import com.qf.oa_system.mapper.TeacherDao;
import com.qf.oa_system.mapper.WeeklyDao;
import com.qf.oa_system.service.TeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * ??ʦ?(Teacher)表服务实现类
 *
 * @author makejava
 * @since 2020-06-03 20:26:31
 */
@Service("teacherService")
public class TeacherServiceImpl implements TeacherService {
    @Resource
    private TeacherDao teacherDao;

    @Resource
    private StudentDao studentDao;

    @Resource
    private WeeklyDao weeklyDao;


    /**
     * 通过ID查询单条数据
     *
     * @param teaId 主键
     * @return 实例对象
     */
    @Override
    public Teacher queryById(Integer teaId) {
        return this.teacherDao.queryById(teaId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Teacher> queryAllByLimit(int offset, int limit) {
        return this.teacherDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param teacher 实例对象
     * @return 实例对象
     */
    @Override
    public Teacher insert(Teacher teacher) {
        this.teacherDao.insert(teacher);
        return teacher;
    }

    /**
     * 修改数据
     *
     * @param teacher 实例对象
     * @return 实例对象
     */
    @Override
    public Teacher update(Teacher teacher) {
        this.teacherDao.update(teacher);
        return this.queryById(teacher.getTeaId());
    }

    /**
     * 通过主键删除数据
     *
     * @param teaId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer teaId) {
        return this.teacherDao.deleteById(teaId) > 0;
    }

    @Override
    public Teacher queryByName(String teaName) {
        return teacherDao.queryByName(teaName);
    }

    @Override
    public List<Student> getStudentInfo(Integer userId) {

        Teacher teacher = getTeacherByUserId(userId);

        Student student = new Student();
        student.setClassId(teacher.getClassId());

        return studentDao.queryAll(student);
    }

    @Override
    public Teacher getTeacherByUserId(Integer uid) {
        return teacherDao.getTeacherByUserId(uid);
    }

    public List<Integer> getNoEntry(){

        return null;
    }

    @Override
    public List<StudentAndSingleScore> getStudentAndScoreByCouAndCla(Integer uid) {

        Teacher teacher = getTeacherByUserId(uid);

        Integer courseId = teacher.getCourseId();
        System.out.println(courseId);
        Integer classId = teacher.getClassId();

        return teacherDao.getStudentAndScoreByCouAndCla(classId, courseId);
    }

    @Override
    public void mark(Integer weekId, Integer score) {

        Weekly weekly = new Weekly();
        weekly.setWeekId(weekId);
        weekly.setFlag(score);

        weeklyDao.update(weekly);
    }

    @Override
    public List<Teacher> getTeaByCourseId(Integer couId) {
        return teacherDao.getTeaByCourseId(couId);
    }


}